<html>
<head>
<title>Country Import</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php

require_once("database.inc.php");
require_once("functions.inc.php");

if (isset($_GET['l']) && is_numeric($_GET['l']) && $_GET['l'] > 0) {
	$leagueid = $_GET['l'];
} else {
	die("no league selected!");
}

$keyword = "tid";
if (isset($_GET['cleanup'])) $keyword = "cleanup";

$lastupdate = getLastUpdate();

$dbh = connect_db("gene");
$dbm = connect_db("dbm");

$leaguenames = getAsocArr("leagues_daily", "LeagueID", "LeagueName", $dbh);

$query = mysql_query("SELECT t.*
	FROM `teams_der` t LEFT JOIN flags_updated u ON t.teamid = u.teamid
	WHERE t.leagueid = $leagueid
	AND t.userid > 0
	AND u.userid IS NULL
	ORDER BY t.activationdate ASC
	LIMIT 100", $dbm) or die (mysql_error());
echo "People from {$leaguenames[$leagueid]} who have never updated their coolness (100 oldest teams max.) <b>(uses data from $lastupdate!)</b><br />\n";
echo "<table>\n";
echo "<tr><th>User<th>Team<th>Activated on<th>\n";
while ($row = mysql_fetch_array($query)) {
	$subquery = mysql_query("SELECT * FROM `teams_$lastupdate` WHERE teamid = {$row['teamid']}",$dbm) or die (mysql_error());
	$subrow = mysql_fetch_array($subquery);
	echo "<tr><td>{$subrow['LoginName']}<td><img src=\"flags/{$subrow['LeagueID']}flag.gif\" border=\"1\"> {$subrow['TeamName']}<td>{$subrow['ActivationDate']}<td><a href=\"coolness.php?$keyword={$subrow['TeamID']}#submit\">upload</a>\n";
}
?>
</body>
</html>
